﻿using System;
using System.Collections.ObjectModel;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using AnnouncementServices;
using Common;
using MySilverlightApplication.Model;

namespace MySilverlightApplication
{
    public class MainPageViewModel : ViewModelBase
    {
        private readonly IAnnouncementsModel _announcementsList;
        public event EventHandler LoadComplete;

        public MainPageViewModel()
            : this(new AnnouncementsModel())
        {
            LoadModel();
        }

        public MainPageViewModel(IAnnouncementsModel announcementsList)
        {
            _announcementsList = announcementsList;
        }

        public void LoadModel()
        {
            _announcementsList.GetAnnouncementList(op =>
            {
                Announcements = op.AsObservableCollection();
                if (LoadComplete != null) LoadComplete(this, null);
            });
        }

        private ObservableCollection<Announcement> _announcements;
        public ObservableCollection<Announcement> Announcements
        {
            get { return _announcements; }
            set
            {
                _announcements = value;
                OnPropertyChanged("Announcements");
            }
        }
    }
}
